package com.stellar.circle.utils;

import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

/**
 * 敏感词工具类
 */
public class SensitiveWordUtil {
    private static final SensitiveWordBs WORD_BS = SensitiveWordBs.newInstance()
            .ignoreCase(true)
            .ignoreWidth(true)
            .ignoreNumStyle(true)
            .init();

    public static SensitiveResult filter(String content) {
        List<String> words = WORD_BS.findAll(content);
        return new SensitiveResult(!words.isEmpty(), words);
    }

    @Data
    @AllArgsConstructor
    public static class SensitiveResult {
        private boolean sensitive;
        private List<String> words;
    }
}